package org.grayrabbit.cloud.core.biz;

import org.grayrabbit.cloud.core.config.ConfiguratorException;
import org.grayrabbit.cloud.core.module.ModuleConstructException;
import org.grayrabbit.cloud.core.module.ModuleException;
import org.grayrabbit.cloud.core.module.NoSuchModuleException;
import org.grayrabbit.cloud.core.rpc.Argument;
import org.grayrabbit.cloud.core.rpc.Result;

public abstract class BizAbstractModule implements BizModule {
	protected String name;
	public void construct(String name) throws ModuleConstructException {
		this.name = name;
	}

	public void deconstruct() {
	}

	public String getName() {
		return this.name;
	}

	public static Result submit(String module,Argument argument,boolean server) throws ModuleException {
		try{
			return (BizResult)BizUtility.getModule(module,server).submit(argument); 
		} catch (NoSuchModuleException e) {
			throw new ModuleException(e);
		}
	}
	
	   public int getProperty(String property,boolean server) throws ModuleConstructException
	   {
	     try
	     {
	       String value = BizUtility.getProperty("module", this.name, property,server);
	       return Integer.parseInt(value);
	     } catch (NumberFormatException e) {
	       throw new ModuleConstructException(e);
	       } catch (ConfiguratorException e) {
	    	   throw new ModuleConstructException(e);
	     }
	   }
	   
	   public String getProp(String property,boolean server) throws ModuleConstructException{
		   try
		     {
		       return BizUtility.getProperty("module", this.name, property,server);
		     }catch (ConfiguratorException e) {
		    	   throw new ModuleConstructException(e);
		     }
	   }
}
